home *** CD-ROM | disk | FTP | other *** search
/ InfoMagic Internet Tools 1993 July / Internet Tools.iso / RockRidge / mail / metamail / contrib / sh-versions / showexternal.orig < prev    next >
Encoding:
Text File  |  1993-05-18  |  5.6 KB  |  241 lines

  1. :
  2. # Copyright (c) 1991 Bell Communications Research, Inc. (Bellcore)
  3. # Permission to use, copy, modify, and distribute this material 
  4. # for any purpose and without fee is hereby granted, provided 
  5. # that the above copyright notice and this permission notice 
  6. # appear in all copies, and that the name of Bellcore not be 
  7. # used in advertising or publicity pertaining to this 
  8. # material without the specific, prior written permission 
  9. # of an authorized representative of Bellcore.  BELLCORE 
  10. # MAKES NO REPRESENTATIONS ABOUT THE ACCURACY OR SUITABILITY 
  11. # OF THIS MATERIAL FOR ANY PURPOSE.  IT IS PROVIDED "AS IS", 
  12. # WITHOUT ANY EXPRESS OR IMPLIED WARRANTIES.
  13.  
  14. # Conversion from C shell to Bourne shell by Z-Code Software Corp.
  15. # Conversion Copyright (c) 1992 Z-Code Software Corp.
  16. # Permission to use, copy, modify, and distribute this material
  17. # for any purpose and without fee is hereby granted, provided
  18. # that the above copyright notice and this permission notice
  19. # appear in all copies, and that the name of Z-Code Software not
  20. # be used in advertising or publicity pertaining to this
  21. # material without the specific, prior written permission
  22. # of an authorized representative of Z-Code.  Z-CODE SOFTWARE
  23. # MAKES NO REPRESENTATIONS ABOUT THE ACCURACY OR SUITABILITY
  24. # OF THIS MATERIAL FOR ANY PURPOSE.  IT IS PROVIDED "AS IS",
  25. # WITHOUT ANY EXPRESS OR IMPLIED WARRANTIES.
  26.  
  27. if test -f /usr/lib/sendmail
  28. then
  29.     MAILCOMMAND=/usr/lib/sendmail
  30. else
  31.     MAILCOMMAND=/bin/mail
  32. fi
  33.  
  34. if test -z "$3"
  35. then
  36.     echo "Usage: showexternal body-file access-type name [site [directory [mode]]]"
  37.     exit 1
  38. fi
  39.  
  40. if [ -z "$METAMAIL_TMPDIR" ]
  41. then
  42.     METAMAIL_TMPDIR=/tmp
  43. fi
  44.  
  45. bodyfile=$1
  46. atype=`echo $2 | tr ABCDEFGHIJKLMNOPQRSTUVWXYZ abcdefghijklmnopqrstuvwxyz`
  47. name=$3
  48.  
  49. site=$4
  50.  
  51. dir=$5
  52.  
  53. mode=$6
  54.  
  55. ctype=`grep -i content-type: $bodyfile | sed -e 's/............: //'`
  56. cenc=`grep -i content-transfer-encoding: $bodyfile | sed -e 's/.........................: //'`
  57. username=""
  58. pass=""
  59. TMPDIR=$METAMAIL_TMPDIR/XXXternal.$$
  60. mkdir $TMPDIR
  61. cd $TMPDIR
  62. NEWNAME="mm.ext.$$"
  63. NEEDSCONFIRMATION=1
  64.  
  65. case $atype in
  66.     anon-ftp)
  67.         echo "This mail message contains a POINTER (reference) to data that is "
  68.         echo not included in the message itself.  Rather, the data can be retrieved 
  69.         echo automatically using anonymous FTP to a site on the network. ;;
  70.         
  71.     ftp)
  72.         echo "This mail message contains a POINTER (reference) to data that is "
  73.         echo not included in the message itself.  Rather, the data can be retrieved 
  74.         echo automatically using the FTP protocol to a site on the network. ;;
  75.  
  76.     mail-server)
  77.         cat > $METAMAIL_TMPDIR/ext.junk.$$ <<!
  78. This mail message contains a POINTER (reference) to data that is not
  79. included in the message itself.  Rather, the data can be retrieved by
  80. sending a special mail message to a mail server on the network.
  81. However, doing this automatically is slightly dangerous, because
  82. someone might be using this mechanism to cause YOU to send obnoxious
  83. mail.  For that reason, the mail message that WOULD be sent is being
  84. shown to you first for your approval.
  85.  
  86. This is the message that will be sent if you choose to go ahead and
  87. retrieve the external data:
  88.  
  89. To: ${name}@${site}:
  90. Subject: Automated Mail Server Request
  91.  
  92. !
  93.         cat $bodyfile >> $METAMAIL_TMPDIR/ext.junk.$$
  94.         more $METAMAIL_TMPDIR/ext.junk.$$
  95.         rm $METAMAIL_TMPDIR/ext.junk.$$ ;;
  96.  
  97.     *)
  98.         NEEDSCONFIRMATION=0 ;;
  99. esac
  100.  
  101. if test $NEEDSCONFIRMATION -ne 0
  102. then
  103.     echo ""
  104.     echo_n "Do you want to proceed with retrieving the external data? [y] "
  105.     read ANS
  106.     case "$ANS" in
  107.         [Nn]*) rm -rf $TMPDIR; exit 0 ;;
  108.     esac
  109. fi
  110.  
  111. case "$atype" in
  112.     anon-ftp | ftp)
  113.         case "$atype" in
  114.         anon-ftp )
  115.             username=anonymous
  116.             pass=`whoami`@`hostname`
  117.             ;;
  118.         esac
  119.  
  120.         if test -z "$site"
  121.         then
  122.             echo_n "Site for ftp access: "
  123.             read site
  124.         fi
  125.         if test -z "$username"
  126.         then
  127.             echo_n "User name at site ${site}: "
  128.             read username
  129.         fi
  130.         if test -z "$pass"
  131.         then
  132.             echo_n "Password for user $username at site ${site}: "
  133.             stty -echo
  134.             read pass
  135.             stty echo
  136.             echo ""
  137.         fi
  138.         if test -z "$dir"
  139.         then
  140.             DIRCMD=""
  141.         else
  142.             DIRCMD="cd $dir"
  143.         fi
  144.         if test -z "$mode"
  145.         then
  146.             MODECMD=""
  147.         else
  148.             MODECMD="type $mode"
  149.         fi
  150.         echo OBTAINING MESSAGE BODY USING FTP
  151.         echo SITE: $site USER: $username
  152.         ${FTP:-ftp} -n <<!
  153. open $site
  154. user $username $pass
  155. $DIRCMD
  156. $MODECMD
  157. get $name $NEWNAME
  158. quit
  159. !
  160.         if test ! -r "$NEWNAME"
  161.         then
  162.             echo FTP failed.
  163.             rm -rf $TMPDIR
  164.             exit 1
  165.         fi
  166.         ;;
  167.  
  168.     afs|local-file)
  169.         if test ! -r $name
  170.         then
  171.             echo File not found
  172.             rm -rf $TMPDIR
  173.             exit 1
  174.         fi
  175.         NEWNAME=$name
  176.         echo GETTING BODY FROM FILE NAMED: $NEWNAME ;;
  177.  
  178.     mail-server)
  179.         if test -z "$bodyfile"
  180.         then
  181.             echo mail-server access-type requires a body file
  182.             rm -rf $TMPDIR
  183.             exit 1
  184.         fi
  185.         echo Subject: Automated Mail Server Request > $NEWNAME
  186.         echo To: ${name}@${site} >> $NEWNAME
  187.         echo "" >> $NEWNAME
  188.         cat $bodyfile >> $NEWNAME
  189.         $MAILCOMMAND -t < $NEWNAME
  190.         if test $? -ne 0
  191.         then
  192.             echo sendmail failed
  193.             rm -rf $TMPDIR
  194.             exit 1
  195.         fi
  196.         rm -rf $TMPDIR
  197.         echo Your $ctype data has been requested from a mail server.
  198.         exit 0 ;;
  199.     *)
  200.         echo UNRECOGNIZED ACCESS-TYPE
  201.         rm -rf $TMPDIR
  202.         exit 1 ;;
  203. esac
  204.  
  205. if test "$cenc" = base64
  206. then
  207.     mmencode -u -b < $NEWNAME > OUT
  208.     mv OUT $NEWNAME
  209. elif test "$cenc" = quoted-printable
  210. then
  211.     mmencode -u -q < $NEWNAME > OUT
  212.     mv OUT $NEWNAME
  213. fi
  214.  
  215. case "$atype" in
  216.     local-file ) metamail -b -c $ctype $NEWNAME ;;
  217.     * ) metamail -b -c "$ctype" $TMPDIR/$NEWNAME ;;
  218. esac
  219.  
  220. if test $? -ne 0
  221. then
  222.     echo metamail failed
  223.     rm -rf $TMPDIR
  224.     exit 1
  225. fi
  226.  
  227. if test ! "$NEWNAME" = "$name"
  228. then
  229.     echo ""
  230.     echo The data just displayed is stored in the file $TMPDIR/$NEWNAME
  231.     echo "Do you want to delete it?"
  232.     rm -i $NEWNAME
  233. fi
  234.  
  235. if test ! -r ${TMPDIR}/${NEWNAME}
  236. then
  237.     cd /
  238.     rmdir $TMPDIR
  239. fi
  240.